package com.leyou.item.client;

import com.leyou.common.vo.PageResult;
import com.leyou.item.dto.*;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@FeignClient(value = "item-service")
public interface ItemClient {

    /**
     *      这个可以满足 id ,
     * 分页查询spu
     * @param page     当前页
     * @param rows     每页大小
     * @param saleable 上架商品或下降商品
     * @param key      关键字
     * @return 当前页商品数据
     */
    @GetMapping("/spu/page")
    public PageResult<SpuDTO> querySpuByPage(
            @RequestParam(value = "page", defaultValue = "1") Integer page,
            @RequestParam(value = "rows", defaultValue = "5") Integer rows,
            @RequestParam(value = "key", required = false) String key,
            @RequestParam(value = "saleable", required = false) Boolean saleable);

    /**
     * 根据spuID查询spuDetail
     *
     * @param id spuID
     * @return SpuDetail
     */
    @GetMapping("/spu/detail")
    public SpuDetailDTO querySpuDetailById(@RequestParam("id") Long id);

    /**
     * 根据spuID查询sku
     * @param id spuID
     * @return sku的集合
     */
    @GetMapping("/sku/of/spu")
    public List<SkuDTO> querySkuBySpuId(@RequestParam("id") Long id);

    /**
     * 查询规格参数
     *
     * @param gid       组id
     * @param cid       分类id
     * @param searching 是否用于搜索
     * @return 规格组集合
     */
    @GetMapping("/spec/params")
    public List<SpecParamDTO> querySpecGroupByCategoryId(
            @RequestParam(value = "gid", required = false) Long gid,
            @RequestParam(value = "cid", required = false) Long cid,
            @RequestParam(value = "searching", required = false) Boolean searching);


    //根据Ids查询品牌信息
    @GetMapping("/brand/list")
    List<BrandDTO> queryBrandByIds(@RequestParam("ids") List<Long> ids);

    @GetMapping("/category/list")
    List<CategoryDTO> queryCategoryByIds(@RequestParam("ids") List<Long> ids);

    //根据spu的id查询spuDTO,里面有spuDetail,skus
    @GetMapping("/spu/{id}")
    public SpuDTO querySpuById(@PathVariable("id") Long id);

    //根据id查询品牌
    @GetMapping("/brand/{id}")
    public BrandDTO queryById(@PathVariable("id") Long id);

    //只根据cid查询规格组的集合
    @GetMapping("/spec/groups/of/categoryList")
    public List<SpecGroupDTO> findSpecGroupByCid(@RequestParam("id") Long id);

    //回显购物车列表,有可能是多个商品所以要用list接受
    @GetMapping("/sku/list")
    public List<SkuDTO> querySkuByIds(@RequestParam("ids") List<Long> ids);

    //减库存
    @PostMapping("/stock/minus")
    public Void minusStock(@RequestBody Map<Long,Integer> cartMap);
}
